from django.db import models



# Create your models here.
# 数据库模型结构参考阿里云远程命令结果存储结构
# https://ecs.console.aliyun.com/?accounttraceid=ee93b1dba00d457190ef9b9df911dcf3drac#/server/i-2zeiosvehx9da7w8ooqu/command-invocation-list?regionId=cn-beijing
class CommandHistory(models.Model):
    cmdId = models.CharField(verbose_name='执行ID', max_length=20)
    status = models.CharField(verbose_name='执行状态',
                              max_length=20,
                              choices=(('success', "执行成功"), ('failed', '执行失败')))
    type = models.CharField(verbose_name='命令类型', max_length=20)
    cmd = models.CharField(verbose_name='命令内容', max_length=20)
    cmdResult = models.CharField(verbose_name='命令输出', max_length=20, null=True, blank=True)
    ExitCode = models.IntegerField(verbose_name='ExitCode', null=True, blank=True)
    StartTime = models.DateTimeField(verbose_name='开始时间', auto_now_add=True)
    RunTime = models.IntegerField(verbose_name='执行时长', null=True, blank=True)

    def __str__(self):
        return  self.cmdId + self.cmd

    class Meta:
        verbose_name = '远程命令历史信息'
        verbose_name_plural = verbose_name


